<?php
class copyFile
{
	public $from;
	public $to;
	public function copyFile($from,$to) {
		$this->createDir($to);
		
		$dir1=opendir($from);
		while ($f1=readdir($dir1))
		{
			if ($f1!='.' && $f1!='..')
			{
				$path2=$from.'/'.$f1;
				if (is_file($path2))
				{
					$file=$path2;
					$newfile=$to.'/'.$f1;
					copy($file, $newfile);
				}
				elseif (is_dir($path2))
				{
					$tos= $to.'/'.$f1;
					$this->copyFile($path2,$tos);
				}
			}
		}
	}
	
	public function createDir($to, $mode=0777 ) {
		if (is_dir($to) || @mkdir($to,$mode)) {
			return true;
		};
		if (!$this->createDir(dirname($to),$mode))
		{
			return false;
		}
		return @mkdir($dir,$mode);
	}
}